﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Web;
using System.Web.SessionState;
using DTcms.Web.UI;
using DTcms.Common;

namespace DTcms.Web.m
{
    /// <summary>
    /// ad_detail 的摘要说明
    /// </summary>
    public class ad_detail : IHttpHandler, IRequiresSessionState
    {
        protected int id = 0;
        public void ProcessRequest(HttpContext context)
        {
            id = DTRequest.GetQueryInt("id", 0);
            if (id == 0)
            {
                return;
            }
            BLL.guanggao bll = new BLL.guanggao();
            Model.guanggao model = bll.GetModel(id);
            //更新阅读数
            bll.UpdateField(id, "hits=hits+1");
            StringBuilder strTxt = new StringBuilder();
            strTxt.Append("{");
            strTxt.Append("\"title\":\"" + model.title + "\",");
            strTxt.Append("\"add_time\":\"" + model.add_time.ToString() + "\",");
            strTxt.Append("\"company_id\":\"" + model.company_id.ToString() + "\",");
            strTxt.Append("\"company_name\":\"" + new BLL.company().GetTitle(model.company_id) + "\",");
            strTxt.Append("\"hits\":" + (Convert.ToInt32(model.hits) + 1) + ",");
            if (model.remark.Contains("shicaiquanzi"))
            {
                if (model.remark.Contains("http://")) { strTxt.Append("\"remark\":\"" + Utils.ClearHtmlExceptA(model.remark.ToString()) + "\""); }
                else { strTxt.Append("\"remark\":\"" + Utils.ClearHtmlExceptA(model.remark.ToString()).Replace("pic.shicaiquanzi", "http://pic.shicaiquanzi") + "\""); }

            }
            else
            {
                strTxt.Append("\"remark\":\"" + Utils.ClearHtmlExceptA(model.remark.ToString()) + "\"");
            }

            //strTxt.Append("\"remark\":\"" + Utils.ClearHtmlExceptA(model.content.ToString()) + "\",");
            //strTxt.Append("\"remark\":\"" + Utils.ClearHtmlExceptA(model.remark.ToString()).Replace("pic.shicaiquanzi", "http://pic.shicaiquanzi") + "\"");
            strTxt.Append("}");
            context.Response.Write(strTxt.ToString());
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}